﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIMain : BaseUI {

    Image bg;
    Image sound;
    Vector2 on = new Vector2(1, 0.5f);
    Vector2 off = new Vector2(0, 0.5f);
    public override void LoadInit(string level = null)
    {
        base.LoadInit(level);
        if(AudioManage.IsonBgMusic)
        {
            bg.rectTransform.pivot =on;
        }
        else
        {
            Debug.Log("1");
            bg.rectTransform.pivot = off;
        }
        if(AudioManage.IsonSoundMusic)
        {
            sound.rectTransform.pivot = on;
        }
        else
        {
            sound.rectTransform.pivot = off;
        }
    }
    public override void BindCompotent(string imgName, GameObject go)
    {
        switch (imgName)
        {
            case "Bg":
                bg = go.GetComponent<Image>();
                break;
            case "Sound":
                sound = go.GetComponent<Image>();
                break;
            default:
                break;
        }
    }
    public override void OnButtonClick(string btnName)
    {
        switch (btnName)
        {
            case "BtnStart":
                UIManager.EnterUI<UISelect>();
                UIManager.ExitUI(this);
                break;
            case "BtnClose":
                Application.Quit();
                break;
            case "BtnBgMusic":
                if (bg.rectTransform.pivot == on)
                {
                    bg.rectTransform.pivot = off;
                    AudioManage.IsonBgMusic = false;
                    AudioManage.BgPlay("music_login");
                }
                else
                {
                    bg.rectTransform.pivot = on;
                    AudioManage.IsonBgMusic = true;
                    AudioManage.BgPlay("music_login");
                }
                break;
            case "BtnSoundMusic":
                if (sound.rectTransform.pivot == on)
                {
                    sound.rectTransform.pivot = off;
                    AudioManage.IsonSoundMusic = false;
                }
                else
                {
                    sound.rectTransform.pivot = on;
                    AudioManage.IsonSoundMusic = true;
                }
                break;

            default:
                break;
        }
    }
	
}
